package com.etc.api;

import com.etc.entity.Fruits;
import com.etc.service.FruitsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author kalista
 * @Description
 * @Date 2020/12/17  11:35
 **/
@WebServlet("/index")
public class IndexServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //准备水果数据
        FruitsService fruitsService =  new FruitsService();
        List<Fruits> fruitsList = fruitsService.findAll();
        //                  key             value
        req.setAttribute("fruitsList",fruitsList);
        req.getRequestDispatcher("/WEB-INF/view/index.jsp").forward(req,resp);
    }

}
